<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Names</title>
<script type="text/javascript">
function validate() {
	
	var reNonWord = /\W/
	var reDigit = /\d/
	var f = document.getElementById("firstName").value;
	var m = document.getElementById("middleInitial").value;
	var l = document.getElementById("lastName").value;
	
	if (reNonWord.test(f) || reDigit.test(f)) {
		alert("Only letters are allowed in the field: 'First name'"); 
		return false;
	}
	
	if (reNonWord.test(m) || reDigit.test(m)) {
		alert("Only letters are allowed in the field: 'Middle initial'");
		return false;
	}
	
	if (reNonWord.test(l) || reDigit.test(l)) {
		alert("Only letters are allowed in the field: 'Last name'");
		return false;
	}
}
</script>

</head>
<body>
<h1>Please enter your name:</h1>
<form method="GET" action="citizenship.jsp" onsubmit="return validate()">
<p>First name: <input type ="text" size="15" name="firstName" id="firstName" />
 Middle initial: <input type ="text" size="1" name="middleInitial" id="middleInitial" />
 Last Name: <input type ="text" size="25" name="lastName" id="lastName"/></p>
<input type="submit" value="Submit"/>
</form>
</body>
</html>